<?php
include 'inc/head.php';
include 'wondershare/configs/site_config.php';

//  `FID`,  `TID`,  `FName`,  `TFName`,  `FType` ,  `TFType`,  `FLength`,  `FIndex`,  `Config`,  `UID`,  `CreateTime`,  `Depositing`,  `ProgramCode`,  `DefaultVal`

$fieldStr = array('UrlRule');
$nameStr = array('文档路径规则');
for($i=0;$i<count($fieldStr);$i++)
{
	$sqlStr .= $fieldStr[$i].", ";
	$titleStr .= "<td>{$nameStr[$i]}</td>";
}

$web_type = $_GET['web_type'];
$sql = "select * from Template where web_type = '{$web_type}' order by TID desc";

//顶级管理员才有新建,删除权限
$editFlag = false;
/*if(($currAdmin->Power & 2047) == 2047 && $currAdmin->parent()==NULL ){
	$editFlag = true;
}*/
$editFlag = true;

if($_POST['doPost'] == "true")
{
	$IDS = $_POST["ID"];
	if(!is_array($IDS))
	{
		alert("请选择要操作的文档");
	}
	if($_POST['action'] == "del")
	{
		$sqlstr = implode(",",$IDS);
		$sql = "delete from Template where TID in ($sqlstr)";
		if($db->query($sql))
		{
			new ActionLog(array("LogType"=>"template_del","Action"=>"$sqlstr\t{$currAdmin->AID}"));
			alert("删除成功","location",$_SERVER["SCRIPT_NAME"]);
		}
	}
	exit;
}


?>
<form method="post" onsubmit="return confirm('该操作不可恢复，确认进行该操作');">
<input type="hidden" value="true" name="doPost">
<div>

<select onchange="document.location.href='?web_type='+this.value">
<?php foreach( $site_name as $k=>$v ){?>
<option value="<?php echo $k;?>" <?php if( $k==$web_type){?>selected="selected"<?php }?>><?php echo $v;?></option>
<?php }?>
<option value="0" <?php if( 0==$web_type){?>selected="selected"<?php }?>>其它</option>
</select>

<?php if($editFlag){?><a href="template.php" style="margin-left:10px;">新建模板</a><?php }?> <span style="margin-left:10px;"><a href="template.php?type=all" style="color:#F00">模板缓存文件全部重新生成</a></span></div>
<table width="90%" cellpadding="1" cellspacing="1" class="list-div">
    	<tr style="font-weight:bold">
		<td width="36">选择</td><td width="66" align="center">操作</td><td>模板名称</td><td>数据库表名</td><?php echo $titleStr;?>
        </tr>
	<?php
	$result = $db->query($sql);
	while($row = $db->fetch_array($result))
	{
		if(strInArray($row[TID], unserialize($currAdmin->TPower)) 
		|| (($currAdmin->Power & 2047) == 2047 && $currAdmin->parent()==NULL 
		|| $row[UID] == $currAdmin->AID
		)){
	?>
	<tr>
		<?php
echo "<td>".($editFlag?"<input type=\"checkbox\" value=\"{$row[TID]}\" name=\"ID[]\">":"")."</td>";
echo "<td align=\"center\"><a href=\"template.php?TID={$row[TID]}&web_type={$web_type}\" target=\"_self\" title=\"修改模板属性\">编辑</a></td>";
echo "<td><a href=\"bin/docList_{$row[TID]}.php\" target=\"_self\" title=\"文档列表\">{$row[TName]}</a></td>";
echo "<td><a href=\"fieldList.php?TID={$row[TID]}\" target=\"_self\" title=\"模板域列表\">{$row[DTName]}</a></td>";
for($i=0;$i<count($fieldStr);$i++){
	echo "<td>".$row[$fieldStr[$i]]."</td>";
}
?>
	</tr>
	<?php
		}
	}
	?>
	<tr>
		<td colspan="5"><?php if($editFlag){?><input type="radio" name="action" value="del">删除<?php }?>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<input type="submit" name="sub" value="提交"></td>
	</tr>
    </table>
<?php
include("inc/foot.php");
?>
